<?php
    header('Access-Control-Allow-Origin: *');
    header('Content-Type:application/json;charset=utf-8');
    $con = mysqli_connect("127.0.0.1","root","root","mydb");
    $uid = $_GET['uid'];
    $status = $_GET['status'];
    if($status == 'student'){
        $sql = "SELECT s.stu_id,s.stu_name,s.stu_sex,f.f_name,m.m_name,c.c_id,c.c_name,y.year FROM stu_info AS s INNER JOIN class_info AS c ON s.class_id = c.c_id INNER JOIN major_table AS m ON c.m_id = m.id INNER JOIN faculty_table AS f ON m.f_id = f.id INNER JOIN year AS y ON c.year = y.id WHERE s.stu_id = '$uid';";
        $res = mysqli_query($con,$sql);
        while($row = mysqli_fetch_array($res)){
            $item = array(
                'stu_id' => $row['stu_id'],
                'stu_name' => $row['stu_name'],
                'stu_sex' => $row['stu_sex'],
                'stu_faculty' => $row['f_name'],
                'stu_major' => $row['m_name'],
                'stu_grade' => $row['year'],
                'stu_class' => $row['c_id'],
                'stu_className' => $row['c_name']
            );
        }
    }else{
        $sql = "SELECT * FROM tch_info WHERE t_id = '$uid';";
        $res = mysqli_query($con,$sql);
        while($row = mysqli_fetch_array($res)){
            $item = array(
                't_id' => $row['t_id'],
                't_name' => $row['t_name'],
                't_sex' => $row['t_sex'],
                't_email' => $row['t_email'],
            );
        }
    }
    
    echo json_encode($item);
    mysqli_close($con);
?>